/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package abstractClasses;

import facades.AbstractFacade;
import interfaces.EntityCreator;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import qualifiers.CreatedEntityEvent;
import qualifiers.PreCreateEntityEvent;

/**
 *
 * @author damfercer
 */
public abstract class AbstractEntityCreator<F extends AbstractFacade,T> implements EntityCreator<T>{
    @Inject
    @PreCreateEntityEvent
    Event<T> preCreateEvent;
    
    @Inject
    @CreatedEntityEvent
    Event<T> createdEvent;

    @Inject
    Instance<F> facadeInstance;
    
    @Override
    public T createEntity(T entity) {
        preCreateEvent.fire(entity);
        F facade=facadeInstance.get();
        facade.create(entity);
        createdEvent.fire(entity);
        return entity;
    }
    
}
